home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / being there / Issues & Ideas / Digital Cash / First Virtual / fv-ftp.txt < prev    next >
Text File  |  1994-10-17  |  9KB  |  144 lines

  1. First Virtual support for FTP servers
  2. *************************************
  3.  
  4. This document describes how to support current information databases on FTP
  5. servers with minimal modifications to server software and no modifications to
  6. client software. For information on supporting your World Wide Web server,
  7. please see our home page at http://www.fv.com 
  8.  
  9. An FTP site that already exists can be upgraded to use the First
  10. Virtual protocols with relative ease, particularly if all information
  11. on that FTP server is going to be assumed to be owned by the same
  12. entity (e.g., for cost recovery). If someone connects and logs in with
  13. the "anonymous" login, then only free information is readable;
  14. however, it is expected that directory listings of for-pay information
  15. will still be permitted, in support of Archie and similar systems. If
  16. someone connects and logs in with the ID of "fvftp" then the password
  17. provided should be a valid First Virtual Account ID, which can be
  18. checked at the time of the login against First Virtual's server and
  19. perhaps against a list of server-specific "deadbeats". Future
  20. retrievals during this login would be billed to that account.
  21.  
  22. Required Software
  23. =================
  24.  
  25. To support billing for FTP downloads, you will need first to obtain the First
  26. Virtual API code from ftp://ftp.fv.com/pub/code/fv-api. You can also obtain
  27. patches for FTP servers from ftp://ftp.fv.com/pub/code/fv-ftpd 
  28.  
  29. Implementation
  30. ++++++++++++++
  31.  
  32. Initially, one may be tempted to use the fv program as is, passing
  33. command-line arguments as necessary. However, there are two problems
  34. with this scheme. The first problem is that the .$ files contain what
  35. some may consider sensitive information that should not be transmitted
  36. to users connecting anonymously. The second is a problem of overhead:
  37. on a heavily-loaded server, an extra two or three popen() calls with
  38. their associated shell and execution overheads may be undesirable. To
  39. this end, the above-described programs have been written as a main()
  40. for a library of routines. There is a routine to initialize and
  41. uninitialize internal data structures (including parsing of .$ files),
  42. calculating costs of a file, and billing an account for the cost of a
  43. file. Most of the underlying machinery (in terms of socket management,
  44. SGCP protocol management, and so on) is also exposed. Using this
  45. library instead of executing separate programs has three advantages:
  46. first, the SGCP socket (if any) is left open between calls, which is
  47. more efficient than reestablishing it for each operation; second, the
  48. overhead of executing separate programs is eliminated, as is the
  49. problems of formatting arguments such that the shell does not corrupt
  50. them; third, popen() need not be rewritten to not use a shell which is
  51. unavailable due to an earlier chroot() call. However, there are some
  52. disadvantages as well. Since the routines execute in the same process
  53. as the FTP server daemon, it is not possible to use suid flags to make
  54. the .$ files visible to the billing routines without being visible to
  55. those downloading files.
  56.  
  57. Because the .$ files should not be visible to those downloading files
  58. (since otherwise someone could cause inconvenience to the server), the
  59. following scheme is used. All .$ files are owned by the user
  60. "ftpadmin," which is distinct from the user "ftp". They are made
  61. readable only to the owner and not writable to anyone. Files in the
  62. upload areas are not readable once created. The ~ftp/bin/ls command is
  63. copied from FV_ls and suid to ftpadmin, which allows it to read the .$
  64. files. Since the anonymous ftp process cannot read these files, it
  65. cannot deliver them even accidentally. On the other hand, it cannot
  66. charge for them either. There are two solutions to this problem. The
  67. first would be to put fv into ~ftp/bin and suid to ftpadmin, spawning
  68. separate processes to do the calculations in the same way FV_ls
  69. does. The second method is to read all the .$ files in the anonymous
  70. area into memory before doing the chroot() call and changing the
  71. effective user id of the daemon process. Since scanning all the
  72. directories might be a time-consuming process, one would periodically
  73. do this scan, accumulate the contents of all .$ files into one file,
  74. and store that file outside of the anonymous FTP area accessible after
  75. the chroot() call or in a file readable only by ftpadmin. If this file
  76. is stored in a standard format, the initialization routines can
  77. automatically load it into memory and retain it, reinitializing
  78. current values from the appropriate parts of memory when needed. The
  79. primary dangers here are bloating of the multiple FTP processes with
  80. .$ information they will likely never use and having the individual .$
  81. files out of synchronization with the collected .$ file. For servers
  82. which are primarily download servers (i.e., those without much upload
  83. activity) or servers with few .$ files, these dangers are
  84. lessened. This latter approach is used in the sample server. The shell
  85. script to rebuild the collected .$ files is fv_regen, which calls
  86. fv_gen_preload.
  87.  
  88. Building the system
  89. +++++++++++++++++++
  90.  
  91. Make the appropriate modifications to your FTP server. Basically, the
  92. following is required: 
  93.  
  94. Where users log in, add a condition to not only check for "ftp" or
  95. "anonymous", but also "fvftp". If the user logs in as "fvftp", call fv_preload()
  96. and fv_init() with the right file names, accept a password, and use fv_check()
  97. to verify its accuracy. If the password is acceptable ("active" is good, "new" is
  98. probably good, and you may want to keep a deadbeat list yourself) then finish
  99. logging in the user as you would for anonymous, but additionally set a flag
  100. that says this is a First Virtual login, and remember the password. Before
  101. sending information, call fv_costof() with the full path name of the file to
  102. determine whether it costs money. If not, continue as normal. If so, make sure
  103. that the First Virtual flag is set, or deny the download with an informative error
  104. message. If the download completes, call fv_chargefor() to bill the user. It's
  105. that simple. 
  106.  
  107. In our sample server, we have also added "This costs money" messages in
  108. several places and inserted a five-second delay before starting transmission of
  109. for-fee files. In addition, we have replaced the "ls" program that normally
  110. resides in ~ftp/bin with one copied from the "fv_ls.c" program, which you must
  111. compile and link (don't forget static linking). This program uses two routines,
  112. "glob" and "realpath", which are linked in from the wu-ftp 2.1c FTP server.
  113. They glob file names and discover the full path of a file given a relative path.
  114. If you are using a WU variant, you should compile your ftpd, then compile and
  115. link fv_ls, using realpath.o and glob.o from the ftpd directory. Otherwise,
  116. replace these routines. 
  117.  
  118. The next step is to parameterize how much you want to charge. If there
  119. is only one account to be creditted, it is probably best to modify
  120. fv_vars.c and compile in the server name, seller, and so on. If you
  121. want multiple sellers, you should probably give each a separate
  122. directory. In any case, the "fv_gen_preload" program should be
  123. run. This program goes through the FTP directory collecting all the .$
  124. files and putting their contents into one "preload" file. This preload
  125. file is loaded into memory by fv_preload() and consulted whenever a .$
  126. file is asked to be loaded by fv_chargefor() or fv_costof(). The
  127. preload program should be rerun any time a .$ file changes, including
  128. creation and deletion. The rationale behind this is to keep users from
  129. downloading .$ files, which may be considered to contain information a
  130. seller might not want an anonymous user downloading. Hence, the .$
  131. files in the anonymous FTP directory should not be readable by the uid
  132. the anonymous fptd process is using. Generally, they are owned by
  133. "ftpadmin" under the group "ftp". All the directories and files in the
  134. anonymous area are owned by "ftpadmin" and group "ftp". They should
  135. generally be group readable, except for the .$ files, which should be
  136. only readable by "ftpadmin". The "preload" file (output by the
  137. fv_gen_preload program) should be outside the area accessible after
  138. the root has been changed with chroot() and readable by the ftpd
  139. process before it changes to user "ftp". Finally, the fv_ls program
  140. (which should probably be called "ls" in the ~ftp/bin directory, just
  141. to stay compatible with non-anonymous FTP connections) should be
  142. setuid and owned by "ftpadmin" in order to allow it to read the .$
  143. files while showing directory listings with prices.
  144.